package com.gitee.feizns.explore.data_structure.linked_list.singly.duplicates;

/**
 * 删除排序链表中的重复元素
 *
 * 输入: 1->1->2
 * 输出: 1->2
 * @author feizns
 * @since 2019/10/29
 */
public class DeleteDuplicates {

    public static void main(String[] args) {

        ListNode node = create();

        deleteDuplicates(node).print();

    }

    private static ListNode create() {
        ListNode tmp = new ListNode(1);
        tmp.next = new ListNode(1);
        tmp.next.next = new ListNode(1);
        tmp.next.next.next = new ListNode(1);
        return tmp;
    }

    public static ListNode deleteDuplicates(ListNode head) {
        ListNode tmp = head;
        while ( tmp != null && tmp.next != null ) {
            if ( tmp.next.val == tmp.val )
                tmp.next = tmp.next.next;
            else
                tmp = tmp.next;
        }
        return head;
    }

}
